package eip.chapter8.expiration.impl;

import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLStreamException;

import org.apache.axiom.om.OMElement;
import org.apache.log4j.Logger;
import org.jibx.runtime.JiBXException;

import eip.chapter8.expiration.RestaurantInquiry;
import eip.chapter8.expiration.RestaurantInquiryService;
import eip.chapter8.expiration.RestaurantResponse;
import eip.util.JibxUtil;
import eip.util.StaxUtil;

/**
 * Facade for the restaurant inquiry service.
 * 
 * @author nl24167
 */
public class RestaurantInquiryWebserviceFacade {

	private final static Logger LOG = Logger.getLogger(RestaurantInquiryWebserviceFacade.class);
	
	public OMElement processInquiry(OMElement input) throws JiBXException, XMLStreamException, FactoryConfigurationError {
		
		LOG.info("Start processing request for restaurant.");
		
		// invoke the real service
		RestaurantInquiryService restaurantService = new RestaurantInquiryServiceImpl();
		RestaurantResponse response = restaurantService.processInquiry(
					(RestaurantInquiry) JibxUtil.unmarshall(input.toString(),RestaurantInquiry.class));
		
		// create the result
		OMElement result = StaxUtil.createOMElement(JibxUtil.marshall(response));
		
		LOG.info("Done processing request for restaurant.");
		return result;
	}
}
